home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / bn_kohonen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  7.3 KB  |  284 lines

  1. /*****************************************************************************
  2.   FILE           : bn_kohonen.c
  3.   SHORTNAME      : bn_kohonen
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : Bignet generator of n-Component Kohonen Networks 
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Marcus Ritt, Marc Seemann 
  10.   DATE           : July 13 1993
  11.  
  12.   CHANGED BY     : Guenter Mamier
  13.   IDENTIFICATION : @(#)bn_kohonen.c    1.3 3/2/94
  14.   SCCS VERSION   : 1.3
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  20.  
  21. ******************************************************************************/
  22.  
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <X11/Xlib.h>
  26. #include <X11/Xutil.h>
  27. #include <X11/Xos.h>
  28. #include <X11/cursorfont.h>
  29. #include <X11/Intrinsic.h>
  30. #include <X11/StringDefs.h>
  31. #include <X11/Shell.h>
  32. #include <X11/Xaw/Box.h>
  33. #include <X11/Xaw/Simple.h>
  34. #include <X11/Xaw/Grip.h>
  35. #include <X11/Xaw/Form.h>
  36. #include <X11/Xaw/SmeBSB.h>
  37. #include <X11/Xaw/SmeLine.h>
  38. #include <X11/Xaw/Viewport.h>
  39. #include <X11/Xaw/Label.h>
  40. #include <X11/Xaw/Toggle.h>
  41. #include <X11/Xaw/Command.h>
  42. #include <X11/Xaw/Cardinals.h>
  43. #include <X11/Xaw/AsciiText.h>
  44. #include <X11/Xaw/Scrollbar.h>
  45.  
  46. #include "ui.h"
  47. #include "glob_typ.h"
  48. #include "kr_ui.h"
  49. #include "ui_mainP.h"
  50. #include "ui_confirmer.h"
  51. #include "ui_textP.h"
  52. #include "ui_utilP.h"
  53. #include "ui_netUpdate.h"
  54. #include "ui_status.h"
  55. #include "ui_xWidgets.h"
  56. #include "ui_fileP.h"
  57. #include "ui_display.h"
  58. #include "ui_event.h"
  59. #include "ui_selection.h"
  60. #include "bn_basics.h"
  61.  
  62. #include "bn_kohonen.ph"
  63.  
  64. /*****************************************************************************
  65.   FUNCTION : bn_createKOHONEN
  66.  
  67.   PURPOSE  : create the kohonen bignet window.
  68.   NOTES    :
  69.   RETURNS  :
  70.  
  71.   UPDATE   : 
  72. ******************************************************************************/
  73.  
  74. void bn_createKOHONEN (void)
  75. {
  76.   Widget   box, panel, create_kohonen, done, dummy;
  77.   Arg      arg[25];
  78.   Cardinal n;
  79.   char     buf[40];
  80.   
  81.  
  82.   if (!kohonen_widget_open) {
  83.     sprintf (buf, "Kohonen Feature Map");
  84.     n = 0;  
  85.     
  86.     XtSetArg(arg[n],XtNminHeight,82); n++;
  87.     XtSetArg(arg[n],XtNminWidth,254); n++;  
  88.     XtSetArg(arg[n],XtNmaxHeight,82); n++;
  89.     XtSetArg(arg[n],XtNmaxWidth,254); n++;
  90.     
  91.     
  92.     baseWidget = 
  93.       XtCreatePopupShell (buf, topLevelShellWidgetClass, ui_toplevel, arg, n); 
  94.     n = 0;  
  95.     box = XtCreateManagedWidget ("box", boxWidgetClass, baseWidget, arg, n);
  96.     panel = XtCreateManagedWidget ("form", formWidgetClass, box, NULL, 0);
  97.     
  98.     dummy= ui_xCreateLabelItem("Components:",panel,80,NULL,NULL);
  99.     Comp = ui_xCreateDialogItem(" ", panel, "", 30, dummy, NULL);
  100.     
  101.     dummy= ui_xCreateLabelItem("X-size:", panel, 80, NULL, dummy);
  102.     Xsize= ui_xCreateDialogItem(" ", panel, "", 30, dummy, Comp);    
  103.     
  104.     dummy= ui_xCreateLabelItem("Y-size:", panel, 80, Xsize, Comp);
  105.     Ysize= ui_xCreateDialogItem(" ", panel, "", 30, dummy, Comp);
  106.     
  107.     create_kohonen = bn_basics_xCreateButtonItem ("create_net",box,NULL,NULL);
  108.     XtAddCallback(create_kohonen,XtNcallback,(XtCallbackProc)create_net_PROC,NULL);
  109.     done = bn_basics_xCreateButtonItem ("done",box,create_kohonen,NULL);
  110.     XtAddCallback(done,XtNcallback,(XtCallbackProc)done_PROC,NULL);
  111.     
  112.     XtPopup (baseWidget, XtGrabNone);
  113.     kohonen_widget_open = 1;
  114.     
  115.   } else ui_confirmOk ("Kohonen Feature Map already open");
  116.  
  117. } /* bn_createKOHONEN */
  118.  
  119.  
  120.  
  121. /*****************************************************************************
  122.   FUNCTION : done_PROC
  123.  
  124.   PURPOSE  : callback function of the done-button. 
  125.   NOTES    :
  126.   RETURNS  :
  127.  
  128.   UPDATE   : june 11 1993
  129. ******************************************************************************/
  130.  
  131. static void done_PROC (void)
  132. {
  133.     XtDestroyWidget (baseWidget);
  134.     kohonen_widget_open = 0;
  135. }
  136.  
  137. /*****************************************************************************
  138.   FUNCTION : create_net_PROC
  139.  
  140.   PURPOSE  : callback function of the create-button. 
  141.   NOTES    :
  142.   RETURNS  :
  143.  
  144.   UPDATE   : june 11 1993
  145. ******************************************************************************/
  146.  
  147. static void create_net_PROC(void)
  148. {
  149.   int create= TRUE;
  150.  
  151.   IUnits= ui_xIntFromAsciiWidget(Comp);
  152.   X     = ui_xIntFromAsciiWidget(Xsize);
  153.   Y     = ui_xIntFromAsciiWidget(Ysize);
  154. /*  OUnits= 1;   release 3.1 will have no output units  G.M.*/
  155.   OUnits= 0;
  156.   HUnits= X*Y;
  157.  
  158.   if ((IUnits>0) && (X>0) && (Y>0)) {
  159.     if(krui_getNoOfUnits() != 0)
  160.       create= ui_confirmYes("Create will erase current network. Create?");
  161.     if (create) {
  162.       krui_deleteNet();
  163.       bn_kohonen_createNet();
  164.       bn_basics_refresh();
  165.       ui_confirmOk("Network created.");
  166.     }
  167.   } else ui_confirmOk("Wrong parameters. Use positive integers.");
  168.  
  169. } /* create_net_PROC */
  170.  
  171. /*****************************************************************************
  172.   FUNCTION : errChk
  173.  
  174.   PURPOSE  : check whether an error occured during a process 
  175.   NOTES    : 
  176.   RETURNS  :
  177.  
  178.   UPDATE   : june 6 1993
  179. ******************************************************************************/
  180.  
  181. static void errChk(krui_err ret)
  182. {
  183.   if (ret != 0) ui_tw_errorMessage(krui_error(ret));
  184.  
  185.  
  186. /*****************************************************************************
  187.   FUNCTION : bn_kohonen_createNet
  188.  
  189.   PURPOSE  : create the Kohonen Network 
  190.   NOTES    : 
  191.   RETURNS  :
  192.  
  193.   UPDATE   : june 6 1993
  194. ******************************************************************************/
  195.  
  196. static void bn_kohonen_createNet(void)
  197. {
  198.   int i,j,unit_no;
  199.   struct PosType    unit_pos;
  200.   krui_err ret;
  201.  
  202.  
  203.   /*  Allocate units */
  204.   
  205.   ret = krui_allocateUnits( HUnits + IUnits );
  206.   errChk( ret );
  207.  
  208.  
  209.   /*  Create standard (input) Units  */
  210.  
  211.   unit_pos.x = 1;
  212.   for (i = 1; i <= IUnits; i++) {
  213.     unit_no = krui_createDefaultUnit();
  214.     if (unit_no < 0)  errChk( unit_no );
  215.     ret = krui_setUnitTType( unit_no, INPUT );
  216.     errChk( ret );
  217.     
  218.     unit_pos.y = (IUnits<Y)?i+(Y-IUnits)/2:i;
  219.     krui_setUnitPosition( unit_no, &unit_pos );
  220.   }
  221.  
  222.  
  223.   /* Create standard hidden Units. The size of the feature map is X*Y */
  224.   
  225.   for (i = 1; i <= Y; i++)
  226.     for (j = 1; j <= X; j++) {
  227.       unit_pos.x = 4+j;
  228.       unit_no = krui_createDefaultUnit();
  229.       if (unit_no < 0)  errChk( unit_no );
  230.       ret = krui_setUnitTType( unit_no, HIDDEN );
  231.       errChk( ret );
  232.       
  233.       unit_pos.y = i;
  234.       krui_setUnitPosition( unit_no, &unit_pos );
  235.     }
  236.   
  237.  
  238.   /* Make connections between input units and hidden units  */
  239.  
  240.   /* set all link weights to zero */
  241.  
  242.   for (i = IUnits + 1; i <= IUnits + HUnits; i++) {
  243.  
  244.       /*  Make hidden unit to current unit  */
  245.       ret = krui_setCurrentUnit( i );
  246.       errChk( ret );
  247.     
  248.       /* (backward) connect current (hidden) unit with input unit */
  249.       for (j = 1; j <= IUnits; j++) {
  250.       ret = krui_createLink( j,0.0);
  251.       errChk( ret );
  252.       }
  253.   } 
  254.          
  255.  
  256.   /*  set the update function  */
  257.  
  258.   ret = krui_setUpdateFunc (KOHONEN_UPDATE_FUNC_NAME);
  259.   errChk( ret );
  260.  
  261.  
  262.   /* set the learning function */
  263.  
  264.   ret = krui_setLearnFunc (KOHONEN_LEARN_FUNC_NAME);
  265.   errChk( ret );
  266.  
  267.  
  268.   /* set the init function */
  269.  
  270.   ret = krui_setInitialisationFunc (KOHONEN_INIT_FUNC_NAME);
  271.   errChk( ret );
  272.  
  273. } /* bn_kohonen_createNet */
  274.  
  275.  
  276.  
  277. /*****************************************************************************
  278.  
  279. ******************************************************************************/
  280.  
  281. /* end of file */
  282. /* lines: 283 */
  283.